package com.me.jingdongshop.ui.adapter;

import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.me.jingdongshop.R;
import com.me.jingdongshop.ui.activity.HomePromotionLettersActivity;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by wuer on 2017/5/7/007.
 * 首页界面商品列表的图片适配器
 */

public class HomeRvPicAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>{
    private RecyclerView recyclerView;
    List<Integer> images=new ArrayList<>();

    public HomeRvPicAdapter() {
        images.add(R.drawable.home_rv_pic1);
        images.add(R.drawable.home_rv_pic2);
        images.add(R.drawable.home_rv_pic3);
        images.add(R.drawable.home_rv_pic4);
        images.add(R.drawable.home_rv_pic5);
        images.add(R.drawable.home_rv_pic6);
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view= LayoutInflater.from(parent.getContext()).inflate(R.layout.home_rv_pic_item,parent,false);
        MyViewHolder viewHolder=new MyViewHolder(view);
        return viewHolder;
    }


    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        MyViewHolder viewHolder= (MyViewHolder) holder;
        viewHolder.mImageView.setImageResource(images.get(position));
    }

    @Override
    public int getItemCount() {
        return images.size();
    }
    //自定义的ViewHolder，持有每个Item的的所有界面元素
    public class MyViewHolder extends RecyclerView.ViewHolder {

        public ImageView mImageView;

        public MyViewHolder(View view) {
            super(view);
            mImageView = (ImageView) view.findViewById(R.id.iv_icon1);
            mImageView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(v.getContext(), HomePromotionLettersActivity.class);
                    v.getContext().startActivity(intent);
                }
            });
        }
    }
}
